package app.itw.tison.cloud.order_service.service.impl;

import app.itw.tison.cloud.model.Order;
import app.itw.tison.cloud.model.OrderItem;
import app.itw.tison.cloud.order_service.service.OrderItemService;
import java.beans.Transient;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;


@Service
public class OrderItemServiceImpl implements OrderItemService {
  //初始化假数据
  public static List<OrderItem> list = new ArrayList<>();

  @Override
  public void Saves(List<OrderItem> orderItems, Order order) {
    //加入商品明细
    for (OrderItem item : orderItems){
        this.list.add(item);
    }
    //加入订单
    OrderServiceImpl.list.add(order);
    System.out.println("保存当前的商品明细");
  }

  @Override
  public OrderItem getOrderItemByID(String id) {
    for (OrderItem orderItem :list) {
      if (orderItem.getId().equals(id)){
        return orderItem;
      }
    }
    return null;
  }

  @Override
  public List<OrderItem> getOrderItemByOID(String oid) {
    List<OrderItem> lists= new ArrayList<OrderItem>();
    list.forEach(itme-> {
      if (itme.getOid().equals(oid)){
        lists.add(itme);
      }
    });
    return lists;
  }
}
